<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%@ attribute name="id" type="java.lang.String" required="true" description="编号" %>
<%@ attribute name="name" type="java.lang.String" required="true" description="输入框名称" %>
<%@ attribute name="value" type="java.lang.String" required="true" description="输入框值" %>
<%@ attribute name="hideBtn" type="java.lang.Boolean" required="false" description="是否显示按钮" %>
<%@ attribute name="disabled" type="java.lang.String" required="false" description="是否限制选择，如果限制，设置为disabled" %>
<i id="${id}Icon" class="fa fa-${not empty value?value:' hide'}"></i>&nbsp;<label id="${id}IconLabel">${not empty value?value:'无'}</label>&nbsp;
<input id="${id}" name="${name}" type="hidden" value="${value}"/><a id="${id}Button" href="javascript:" class="btn btn-default ${disabled} ${hideBtn ? 'hide' : ''}">选择</a>&nbsp;&nbsp;
<script type="text/javascript">
    $(function () {
        // 是否限制选择,如果限制,设置为disabled
        if ($("#${id}Button").hasClass("disabled")) {
            return true;
        }
        $("#${id}Button").unbind('click').click(function () {
            bootbox.dialog({
                message: getIframe("${ctx}/tag/iconselect?value=" + $("#${id}").val()),
                title: "选择图标",
                size: "large",
                buttons: {
                    cancel: {
                        label: "关闭",
                        callback: function () {
                            $("#${id}Id").val("");
                            $("#${id}Name").val("");
                        }
                    },
                    ok: {
                        label: "确定",
                        callback: function () {
                            var innerIframe = $(document).find("iframe")[0];
                            if (innerIframe == null) return false;
                            var icon = $(innerIframe).contents().find("#icon").val();
                            $("#${id}Icon").attr("class", "fa " + icon);
                            $("#${id}IconLabel").text(icon);
                            $("#${id}").val(icon);
                        }
                    }
                }
            });
        });

        function getIframe(url) {
            var newIframeObject = document.createElement("iframe");
            newIframeObject.src = url;
            newIframeObject.scrolling = "no";
            newIframeObject.frameBorder = 0;
            newIframeObject.width = "100%";
            newIframeObject.height = "500px";
            newIframeObject.style.border = "none";
            return newIframeObject;
        }
    });
</script>